/*
 * Copyright (c) 2020 Texas Instruments Incorporated - http://www.ti.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * *  Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * *  Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * *  Neither the name of Texas Instruments Incorporated nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

#ifndef BOARD_H
#define BOARD_H

//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif

//
// Included Files
//

#include "driverlib.h"
#include "device.h"

//*****************************************************************************
//
// PinMux Configurations
//
//*****************************************************************************

//
// EPWM1 -> myEPWM0 Pinmux
//
//
// EPWM1_A - GPIO Settings
//
#define GPIO_PIN_EPWM1_A 0
#define myEPWM0_EPWMA_GPIO 0
#define myEPWM0_EPWMA_PIN_CONFIG GPIO_0_EPWM1_A
//
// EPWM1_B - GPIO Settings
//
#define GPIO_PIN_EPWM1_B 1
#define myEPWM0_EPWMB_GPIO 1
#define myEPWM0_EPWMB_PIN_CONFIG GPIO_1_EPWM1_B
//
// GPIO30 - GPIO Settings
//
#define DO_DSP_LED_O_GPIO_PIN_CONFIG GPIO_30_GPIO30
//
// GPIO14 - GPIO Settings
//
#define DI_Liquid_level_DSP_GPIO_PIN_CONFIG GPIO_14_GPIO14
//
// GPIO34 - GPIO Settings
//
#define DO_MOTOR_PS_EN_GPIO_PIN_CONFIG GPIO_34_GPIO34
//
// GPIO15 - GPIO Settings
//
#define DO_PUMP_PS_EN_GPIO_PIN_CONFIG GPIO_15_GPIO15
//
// GPIO9 - GPIO Settings
//
#define DO_DSP_dir_PUMP_O_GPIO_PIN_CONFIG GPIO_9_GPIO9

//
// SCIB -> mySCIB Pinmux
//
//
// SCIB_RX - GPIO Settings
//
#define GPIO_PIN_SCIB_RX 13
#define mySCIB_SCIRX_GPIO 13
#define mySCIB_SCIRX_PIN_CONFIG GPIO_13_SCIB_RX
//
// SCIB_TX - GPIO Settings
//
#define GPIO_PIN_SCIB_TX 12
#define mySCIB_SCITX_GPIO 12
#define mySCIB_SCITX_PIN_CONFIG GPIO_12_SCIB_TX

//
// SCIA -> mySCIA Pinmux
//
//
// SCIA_RX - GPIO Settings
//
#define GPIO_PIN_SCIA_RX 28
#define mySCIA_SCIRX_GPIO 28
#define mySCIA_SCIRX_PIN_CONFIG GPIO_28_SCIA_RX
//
// SCIA_TX - GPIO Settings
//
#define GPIO_PIN_SCIA_TX 29
#define mySCIA_SCITX_GPIO 29
#define mySCIA_SCITX_PIN_CONFIG GPIO_29_SCIA_TX

//*****************************************************************************
//
// ADC Configurations
//
//*****************************************************************************
#define ADCB_OBJ_BASE ADCB_BASE
#define ADCB_OBJ_RESULT_BASE ADCBRESULT_BASE
#define ADCB_OBJ_SOC_BIT_P24V ADC_SOC_NUMBER0
#define ADCB_OBJ_FORCE_SOC_BIT_P24V ADC_FORCE_SOC0
#define ADCB_OBJ_SAMPLE_WINDOW_SOC_BIT_P24V 5120
#define ADCB_OBJ_TRIGGER_SOURCE_SOC_BIT_P24V ADC_TRIGGER_CPU1_TINT0
#define ADCB_OBJ_CHANNEL_SOC_BIT_P24V ADC_CH_ADCIN4
#define ADCB_OBJ_SOC_Temperature ADC_SOC_NUMBER1
#define ADCB_OBJ_FORCE_SOC_Temperature ADC_FORCE_SOC1
#define ADCB_OBJ_SAMPLE_WINDOW_SOC_Temperature 5120
#define ADCB_OBJ_TRIGGER_SOURCE_SOC_Temperature ADC_TRIGGER_CPU1_TINT0
#define ADCB_OBJ_CHANNEL_SOC_Temperature ADC_CH_ADCIN14
void ADCB_OBJ_init();

#define ADCC_OBJ_BASE ADCC_BASE
#define ADCC_OBJ_RESULT_BASE ADCCRESULT_BASE
#define ADCC_OBJ_SOC_Sense_P_dsp ADC_SOC_NUMBER0
#define ADCC_OBJ_FORCE_SOC_Sense_P_dsp ADC_FORCE_SOC0
#define ADCC_OBJ_SAMPLE_WINDOW_SOC_Sense_P_dsp 5120
#define ADCC_OBJ_TRIGGER_SOURCE_SOC_Sense_P_dsp ADC_TRIGGER_CPU1_TINT0
#define ADCC_OBJ_CHANNEL_SOC_Sense_P_dsp ADC_CH_ADCIN0
void ADCC_OBJ_init();


//*****************************************************************************
//
// ASYSCTL Configurations
//
//*****************************************************************************

//*****************************************************************************
//
// CPUTIMER Configurations
//
//*****************************************************************************
#define TaskTimer0_BASE CPUTIMER0_BASE
void TaskTimer0_init();

//*****************************************************************************
//
// DAC Configurations
//
//*****************************************************************************
#define DSP_DACA_OUT_BASE DACA_BASE
void DSP_DACA_OUT_init();
#define DSP_DACB_OUT_BASE DACB_BASE
void DSP_DACB_OUT_init();

//*****************************************************************************
//
// EPWM Configurations
//
//*****************************************************************************
#define myEPWM0_BASE EPWM1_BASE
#define myEPWM0_TBPRD 25000
#define myEPWM0_COUNTER_MODE EPWM_COUNTER_MODE_UP_DOWN
#define myEPWM0_TBPHS 0
#define myEPWM0_CMPA 0
#define myEPWM0_CMPB 0
#define myEPWM0_CMPC 0
#define myEPWM0_CMPD 0
#define myEPWM0_DBRED 0
#define myEPWM0_DBFED 0
#define myEPWM0_TZA_ACTION EPWM_TZ_ACTION_HIGH_Z
#define myEPWM0_TZB_ACTION EPWM_TZ_ACTION_HIGH_Z
#define myEPWM0_INTERRUPT_SOURCE EPWM_INT_TBCTR_DISABLED

//*****************************************************************************
//
// FLASH Configurations
//
//*****************************************************************************
#define myFMC0_BASE FLASH0CTRL_BASE
#define myFMC0_ECCBASE FLASH0ECC_BASE
#define myFMC0_WAITSTATES 4
#define myFMC0_ERRORTHRESHOLD 0

//*****************************************************************************
//
// GPIO Configurations
//
//*****************************************************************************
#define DO_DSP_LED_O 30
void DO_DSP_LED_O_init();
#define DI_Liquid_level_DSP 14
void DI_Liquid_level_DSP_init();
#define DO_MOTOR_PS_EN 34
void DO_MOTOR_PS_EN_init();
#define DO_PUMP_PS_EN 15
void DO_PUMP_PS_EN_init();
#define DO_DSP_dir_PUMP_O 9
void DO_DSP_dir_PUMP_O_init();

//*****************************************************************************
//
// INTERRUPT Configurations
//
//*****************************************************************************

// Interrupt Settings for INT_TaskTimer0
#define INT_TaskTimer0 INT_TIMER0
#define INT_TaskTimer0_INTERRUPT_ACK_GROUP INTERRUPT_ACK_GROUP1
extern __interrupt void INT_TaskTimer0_ISR(void);

// Interrupt Settings for INT_mySCIB_RX
#define INT_mySCIB_RX INT_SCIB_RX
#define INT_mySCIB_RX_INTERRUPT_ACK_GROUP INTERRUPT_ACK_GROUP9
extern __interrupt void INT_mySCIB_RX_ISR(void);

// Interrupt Settings for INT_mySCIB_TX
#define INT_mySCIB_TX INT_SCIB_TX
#define INT_mySCIB_TX_INTERRUPT_ACK_GROUP INTERRUPT_ACK_GROUP9
extern __interrupt void INT_mySCIB_TX_ISR(void);

// Interrupt Settings for INT_mySCIA_RX
#define INT_mySCIA_RX INT_SCIA_RX
#define INT_mySCIA_RX_INTERRUPT_ACK_GROUP INTERRUPT_ACK_GROUP9
extern __interrupt void INT_mySCIA_RX_ISR(void);

// Interrupt Settings for INT_mySCIA_TX
#define INT_mySCIA_TX INT_SCIA_TX
#define INT_mySCIA_TX_INTERRUPT_ACK_GROUP INTERRUPT_ACK_GROUP9
extern __interrupt void INT_mySCIA_TX_ISR(void);

//*****************************************************************************
//
// SCI Configurations
//
//*****************************************************************************
#define mySCIB_BASE SCIB_BASE
#define mySCIB_BAUDRATE 115200
#define mySCIB_CONFIG_WLEN SCI_CONFIG_WLEN_8
#define mySCIB_CONFIG_STOP SCI_CONFIG_STOP_TWO
#define mySCIB_CONFIG_PAR SCI_CONFIG_PAR_NONE
#define mySCIB_FIFO_TX_LVL SCI_FIFO_TX0
#define mySCIB_FIFO_RX_LVL SCI_FIFO_RX1
void mySCIB_init();
#define mySCIA_BASE SCIA_BASE
#define mySCIA_BAUDRATE 115200
#define mySCIA_CONFIG_WLEN SCI_CONFIG_WLEN_8
#define mySCIA_CONFIG_STOP SCI_CONFIG_STOP_ONE
#define mySCIA_CONFIG_PAR SCI_CONFIG_PAR_ODD
#define mySCIA_FIFO_TX_LVL SCI_FIFO_TX0
#define mySCIA_FIFO_RX_LVL SCI_FIFO_RX1
void mySCIA_init();

//*****************************************************************************
//
// SYNC Scheme Configurations
//
//*****************************************************************************

//*****************************************************************************
//
// SYSCTL Configurations
//
//*****************************************************************************

//*****************************************************************************
//
// Board Configurations
//
//*****************************************************************************
void	Board_init();
void	ADC_init();
void	ASYSCTL_init();
void	CPUTIMER_init();
void	DAC_init();
void	EPWM_init();
void	FLASH_init();
void	GPIO_init();
void	INTERRUPT_init();
void	SCI_init();
void	SYNC_init();
void	SYSCTL_init();
void	PinMux_init();

//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif

#endif  // end of BOARD_H definition
